package com.esun.rabbit2.communicaters.recharg;

import com.esun.config.Config;
import com.esun.model.UserInfo;
import com.esun.util.log.EDebug;
import com.esun.util.md5.MD5;

/**
 * @ClassName:RechargeController
 * @Description:充值控制类 ,提供充值相关的交互内容和方法
 * @author: City jiangsy@500wan.com
 * @date: 2011-2-17 下午12:22:42
 * 
 */
public class RechargeController {

	// 银行类型
	private String bankType;

	// 银行地区
	// private String bankArea;

	// 银行名称
	private String bankName;

	// 银行卡号
	private String bindingCardNum;

	// 用户真实姓名
	private String realUserName;

	// 用户身份证号
	private String userIDNum;

	// 用户密码

	// 银行地址
	private String bankAdress;

	// 提款金额
	private String withdrawAmount;

	// 返回信息
	private String strResult;

	private String msg;

	/**
	 * @Title: isBindingCardOk
	 * @Description: 绑定银行卡
	 * @param： bankType 0 招商银行；2 工商银行；3 建设银行；1 其他银行
	 * @param： bankName 对应银行的名称
	 * @param： cardNum 银行卡号
	 * @param： userRealName 用户真实姓名
	 * @param： userIdentityNum 身份证号码
	 * @param： bankAdress 银行地址信息
	 * @param： bankZone 深圳是0 非深圳是1
	 * @return： boolean 是否绑定成功
	 */
	public boolean isBindingCardOk(String bankType, String bankName, String cardNum, String userRealName, String userIdentityNum, String bankAdress, String bankZone) {
		String password = UserInfo.getUserInfo().getUserPwd();
		if (password.length() != 32) {
			password = MD5.md5(password);
		}

		String stringBody = bankType + DataShare.ONESPACE + bankZone + DataShare.ONESPACE + bankName + DataShare.ONESPACE + cardNum + DataShare.ONESPACE + userRealName
				+ DataShare.ONESPACE + userIdentityNum + DataShare.ONESPACE + password + DataShare.ONESPACE + bankAdress;

		EDebug.o(this, "binding info is : " + stringBody);

		// 银行类型,银行地区,银行名称,银行卡号,用户真实姓名,用户身份证号码,用户密码,银行地址
		Bussiness10116 b10116 = new Bussiness10116(RechargeUserInfo.getUserInfo().getSessionId(), stringBody, DataShare.USER_BINDINGCARD, DataShare.CT_NONE, DataShare.ET_NONE);

		strResult = "";
		for (int i = 0; i < b10116.getResult().length; i++) {
			strResult += b10116.getResult()[i];
		}
		boolean isOk = false;
		if (strResult.indexOf(Config.NUM100) > -1) {
			isOk = true;
		} else {
			isOk = false;
		}
		msg = strResult;
		return isOk;
	}

	// 验证绑定银行卡是否支持手机银行充值
	public boolean isCanPhoneRecharge() {

		Bussiness10017 b10017 = new Bussiness10017(RechargeUserInfo.getUserInfo().getSessionId(), "", DataShare.USER_ISCANPHONERECHARGE, DataShare.CT_NONE, DataShare.ET_NONE);
		strResult = "";
		for (int i = 0; i < b10017.getResult().length; i++) {
			strResult += b10017.getResult()[i];
		}
		boolean isOk = false;
		if (strResult.indexOf(Config.NUM100) > -1) {
			isOk = true;
		} else {
			isOk = false;
		}
		if (strResult.indexOf("银联不支持") > -1) {
			msg = "非常抱歉，你当前的绑定的银行卡不支持银联电话回呼业务，如您想使用该充值方式请拨打:0755-86330000 咨询。";
		} else {
			msg = strResult;
		}
		return isOk;
	}

	/**
	 * @Title: isWithdrawAmountOk
	 * @Description: 是否提款成功
	 * @param realUserName
	 *            ： 用户真实姓名
	 * @param: withdrawAmount 提款金额
	 * @param: phoneNum 电话号码
	 * @return: boolean 是否提款成功
	 */
	public boolean isWithdrawAmountOk(String realUserName, String withdrawAmount, String phoneNum) {
		Bussiness10018 bussiness10018 = new Bussiness10018(RechargeUserInfo.getUserInfo().getSessionId(), realUserName + DataShare.ONESPACE + withdrawAmount + DataShare.ONESPACE
				+ phoneNum, DataShare.USER_WITHDRAW, DataShare.CT_NONE, DataShare.ET_NONE);
		EDebug.o(">>>>>>>>>>" + realUserName + DataShare.ONESPACE + withdrawAmount + DataShare.ONESPACE + phoneNum);
		strResult = "";
		for (int i = 0; i < bussiness10018.getResult().length; i++) {
			strResult += bussiness10018.getResult()[i];
		}
		boolean isOk = false;
		if (strResult.indexOf(Config.NUM100) > -1) {
			isOk = true;
		} else {
			isOk = false;
		}
		msg = strResult;
		return isOk;
	}

	/**
	 * @Title: isSzxRechargeOk
	 * @Description: 神州行手机充值
	 * @param cardNum
	 *            充值卡号
	 * @param cardPsw
	 *            充值卡密码
	 * @param cardAmount
	 *            充值卡面额
	 * @param cardType
	 *            充值卡类型 1：移动 2：联通
	 * @return boolean 是否充值成功
	 * @throws
	 */
	public boolean isSzxRechargeOk(String cardNum, String cardPsw, String cardAmount, String cardType) {

		String password = UserInfo.getUserInfo().getUserPwd();

		if (password.length() != 32) {
			password = MD5.md5(password);
		}
		String strBody = UserInfo.getUserInfo().getUserName() + DataShare.ONESPACE + password + DataShare.ONESPACE + "2027" + DataShare.ONESPACE + cardAmount + DataShare.ONESPACE
				+ cardNum + DataShare.ONESPACE + cardPsw + DataShare.ONESPACE + cardType + DataShare.ONESPACE + "android";
		Bussiness10010 b10010 = new Bussiness10010(RechargeUserInfo.getUserInfo().getSessionId(), strBody, DataShare.USER_SZXRECHARGE, DataShare.CT_NONE, DataShare.ET_NONE);
		EDebug.o("City==============>>>>>>>>>>>>>" + strBody);
		strResult = "";
		for (int i = 0; i < b10010.getResult().length; i++) {
			strResult += b10010.getResult()[i];
		}
		boolean isOk = false;
		if (strResult.indexOf(Config.NUM100) > -1) {
			isOk = true;
		} else {
			isOk = false;
		}
		msg = strResult;
		return isOk;
	}

	/**
	 * @Title: isSZFRechargeSucceed
	 * @Description: 神州付手机充值
	 * @param cardNum
	 *            充值卡号
	 * @param cardPsw
	 *            充值卡密码
	 * @param cardAmount
	 *            充值卡面额
	 * @param cardType
	 *            充值卡类型 0：移动 1：联通2:电信
	 * @return boolean 是否充值成功
	 * @throws
	 */
	public boolean isSZFRechargeSucceed(String cardNum, String cardPsw, String cardAmount, String cardType, String IMEI) {
		EDebug.o(this, "神州付手机充值接口");
		String password = UserInfo.getUserInfo().getUserPwd();
		if (password.length() != 32) {
			password = MD5.md5(password);
		}
		strResult = "";
		String strBody = UserInfo.getUserInfo().getUserName() + DataShare.ONESPACE + password + DataShare.ONESPACE + "2169" + DataShare.ONESPACE + cardAmount + DataShare.ONESPACE
				+ cardNum + DataShare.ONESPACE + cardPsw + DataShare.ONESPACE + cardType + DataShare.ONESPACE + "android" + DataShare.ONESPACE + IMEI;

		Bussiness10028 b10028 = new Bussiness10028(RechargeUserInfo.getUserInfo().getSessionId(), strBody, DataShare.USER_SZFRECHARGE, DataShare.CT_NONE, DataShare.ET_NONE);

		EDebug.o(this, "b10028.getResult().length =" + b10028.getResult().length);
		for (int i = 0; i < b10028.getResult().length; i++) {
			EDebug.o(this, b10028.getResult()[i]);
			strResult += b10028.getResult()[i];
		}
		boolean isOk = false;
		if (strResult.indexOf(Config.NUM100) > -1) {
			isOk = true;
		} else {
			isOk = false;
		}
		EDebug.o(this, "isOK = " + isOk + "strresult = " + strResult);
		msg = strResult;
		return isOk;

	}

	// 银联充值
	public boolean isYlRechargeOk(String phoneNum, String amount) {

		String password = UserInfo.getUserInfo().getUserPwd();

		if (password.length() != 32) {
			password = MD5.md5(password);
		}
		String strBody = UserInfo.getUserInfo().getUserName() + DataShare.ONESPACE + password + DataShare.ONESPACE + amount + DataShare.ONESPACE + phoneNum + DataShare.ONESPACE
				+ "android";
		Bussiness10016 b10016 = new Bussiness10016(RechargeUserInfo.getUserInfo().getSessionId(), strBody, DataShare.USER_YINLIANRECHARGE, DataShare.CT_NONE, DataShare.ET_NONE);
		strResult = "";
		for (int i = 0; i < b10016.getResult().length; i++) {
			strResult += b10016.getResult()[i];
		}
		boolean isOk = false;
		if (strResult.indexOf(Config.NUM100) > -1) {
			isOk = true;
		} else {
			isOk = false;
		}
		msg = strResult;
		return isOk;
	}

	public String getMSG() {
		return msg;
	}

	public String getBindingCardNum() {
		return bindingCardNum;
	}

	public void setBindingCardNum(String bindingCardNum) {
		this.bindingCardNum = bindingCardNum;
	}

	public String getWithdrawAmount() {
		return withdrawAmount;
	}

	public void setWithdrawAmount(String withdrawAmount) {
		this.withdrawAmount = withdrawAmount;
	}

	public String getBankType() {
		return bankType;
	}

	public void setBankType(String bankType) {
		this.bankType = bankType;
	}

	// public String getBankArea() {
	// return bankArea;
	// }
	//
	// public void setBankArea(String bankArea) {
	// this.bankArea = bankArea;
	// }

	public String getBankName() {
		return bankName;
	}

	public void setBankName(String bankName) {
		this.bankName = bankName;
	}

	public String getRealUserName() {
		return realUserName;
	}

	public void setRealUserName(String realUserName) {
		this.realUserName = realUserName;
	}

	public String getUserIDNum() {
		return userIDNum;
	}

	public void setUserIDNum(String userIDNum) {
		this.userIDNum = userIDNum;
	}

	public String getBankAdress() {
		return bankAdress;
	}

	public void setBankAdress(String bankAdress) {
		this.bankAdress = bankAdress;
	}

}
